layui.use(['jquery', 'element', 'layer', 'form', 'layedit'], function () {
    var $ = layui.$;
    var layedit = layui.layedit;
    var form = layui.form;
    var ctxPath = "/education";

    /**
     * 详情富文本
     */
    /* var detailEditId = layedit.build('detail', {
     height: 500,
     uploadImage :  {
     url: ctxPath + '/file/uploadPic',
     type: 'post',
     }
     });*/

    /**
     * 初始化积分订单详情方法
     * @param id
     */
    var initPointRewardOrder = function (id) {
        $.ajax({
            url: ctxPath + '/api/pointRewardOrder/findById',
            type: 'post',
            dataType: 'json',
            data: {id: id},
            success: function (result) {
                if(result.code == 0) {
                    var data = result.data;
                    if (data != null) {
                        $("input[name='id']").val(data.id);
                        $("input[name='orderCode']").val(data.orderCode);
                        $("input[name='totalPrice']").val(data.totalPrice);
                        $("input[name='customerName']").val(data.customerName);
                        $("input[name='phone']").val(data.phone);
                        $("input[name='expressNo']").val(data.expressNo);
                        $("input[name='address']").val(data.address);
                        $("input[name='remarks']").val(data.remarks);
                    }
                } else {
                    layer.alert("get data fail：" + result.msg);
                }
            }
        });

        $.ajax({
            url: ctxPath + '/api/pointRewardOrder/findDetailById',
            type: 'post',
            dataType: 'json',
            data: {id: id},
            success: function (result) {
                if(result.code == 0) {
                    var data = result.data;
                    if (data != null) {
                        $("input[name='items']").val(data);
                    }
                } else {
                    layer.alert("get data fail：" + result.msg);
                }
            }
        });
    };

    /**
     * 初始化游学产品
     * @type {string}
     */
    initPointRewardOrder(window.location.search.substring(4));

    $("#saveBtn").click(function () {
        var request = {
            id: $("input[name='id']").val(),
            orderCode: $("input[name='orderCode']").val(),
            totalPrice: $("input[name='totalPrice']").val(),
            customerName: $("input[name='customerName']").val(),
            phone: $("input[name='phone']").val(),
            expressNo: $("input[name='expressNo']").val(),
            address: $("input[name='address']").val(),
            remarks: $("input[name='remarks']").val()
        };

        $.ajax({
            url: ctxPath + "/api/pointRewardOrder/modify",
            data: JSON.stringify(request),
            type: 'post',
            dataType: 'json',
            contentType: 'application/json',
            success: function (result) {
                if (result.code == 0) {
                    layer.alert('保存成功！', function (index) {
                        layer.close(index);
                        location.href = ctxPath + '/html/pointReward/pointRewardOrderList.html';
                    });
                } else {
                    layer.alert("保存失败：" + result.msg);
                }
            }
        });
    });
});

